import { customTable } from '@/components/ProTable/interface';
import { ProTableValue } from '@/interface/public';
import { useAddForm } from './use-addForm';
/**
 * @name 系统全局配置
 */
export function useDataGrid(proTableBox: ProTableValue) {
  const { addForm, saveAddForm } = useAddForm(proTableBox);
  let dataGrid = reactive<customTable>({
    initParam: {},
    // 表格配置项
    columns: [
      { prop: 'operation', label: 'operation', fixed: 'left', width: 80 },
      {
        label: '编号',
        prop: 'setKey',
        search: {
          el: 'input',
          key: 'setKey',
          defaultValue: ''
        }
      },
      {
        label: '值',
        prop: 'setValue'
      },
      {
        label: '描述',
        prop: 'setMark'
      },
      {
        label: '备注',
        prop: 'remark'
      }
    ],
    headButtonList: [],
    rowButtonList: [
      {
        label: 'edit',
        type: 'primary',
        // permissionCode: "system:save",
        methods: (row: any) => {
          row.value = row.svalue;
          formOpen(addForm, 'edit', row);
        },
        attrs: {
          link: true
        }
      }
    ]
  });

  const dataCallBack = data => {
    let newData = [];
    Object.keys(data).forEach(key => {
      newData.push({
        ...data[key],
        code: key
      });
    });
    return newData;
  };
  return { dataGrid, addForm, saveAddForm, dataCallBack };
}
